package com.edu.controller;

import com.edu.dao.MyBatisDaoImpl;
import com.edu.data.Admin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.SessionAttributes;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/login")
@SessionAttributes(value={"admin","key","contactList"})  //@SessionAttributes 声明session预定的key值
public class LoginController {
    @Autowired
    MyBatisDaoImpl dao;
    @RequestMapping("/toLogin")
    public String  toLogin(){
        return "login";
    }

    @RequestMapping("/login")
    public String login(@RequestParam(value="account")String accout, @RequestParam(value="password")String password, Model model, HttpServletRequest request){
        Admin admin=dao.login(accout,password);
        //request.getSession().setAttribute("admin",admin);
        model.addAttribute("admin", admin);
        String name="张三";
        String name1="李四";
        model.addAttribute("key",name);
        model.addAttribute("key",name1);
        return "redirect:/contact/admin";
    }
}
